package com.liuyuan.controller;

import com.liuyuan.pojo.Book;
import com.liuyuan.pojo.News;
import com.liuyuan.pojo.User;
import com.liuyuan.service.BookService;
import com.liuyuan.service.NewsService;
import com.liuyuan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//一个controller可以调用多个service
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private NewsService newsService;


    @RequestMapping("/getUserById")
    public User getUserById(int id){
        User user = userService.getUserById(id);
        return user;
    }

    @RequestMapping("/getAllUser")
    public List<User> getAllUser(){
        return userService.getAllUser();

    }

@RequestMapping("/addUser")
        public int addUser(@RequestBody User user){
        return userService.addUser(user);
}

@RequestMapping ("/updateUser")
        public int updateUser(@RequestBody User user){
        return userService.updateUser(user);
}

@RequestMapping("/deleteUser")
    public int deleteUser(int id){
        return userService.deleteUser(id);
}

@RequestMapping("/getNewsById")
    public News getNewsById(int id) {
    return newsService.getNewsById(id);
}

@RequestMapping("/getAllNews")
    public  List<News> getAllNews() {
        return newsService.getAllNews();
    }

    @RequestMapping("/insertNews")
    public int insertNews(@RequestBody News news){
        return newsService.insertNews(news);
   }

   @RequestMapping("/updateNews")
    public int updateNews(@RequestBody News news){
        return newsService.updateNews(news);
   }

   @RequestMapping("/deleteNews")
    public int deleteNews(int id){
        return newsService.deleteNews(id);}
}
